<template>
	<view class="h-fill">
		<view v-if="list.length">
			<uni-list>
				<uni-list-item v-for="(item, index) in list" @click="handleItemClick(item)"
					:key="item.id" :title="item.amount + '元'" :note="item.createTime">
					<template v-slot:right="">
						<text :style="{color: withdrawStatus[item.status].color}">{{withdrawStatus[item.status].label}}</text>
					</template>
				</uni-list-item>
			</uni-list>
			<uni-load-more :status="loadingStatus"></uni-load-more>
		</view>
		<u-empty v-else></u-empty>
		<uni-popup ref="popup">
			<view class="simple-card round-corner">
				<view v-if="selectedItem">
					<view class="uni-flex uni-column" v-if="selectedItem.status === 'REJECTED'">
						<text class="uni-bold">已驳回</text>
						<text>原因：{{selectedItem.auditMsg || '-'}}</text>
					</view>
					<view class="uni-flex uni-column" v-else-if="selectedItem.status === 'WAITING'">
						<text>审核中，请等待。。。</text>
					</view>
					<view v-else class="uni-flex uni-column">
						<text class="uni-bold">已通过</text>
						<text>通过审核，平台已打款，请留言微信通知！</text>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {getMemberWithdrawList} from "../../api/trade.js";
	import {withdrawStatus} from "../../common/constants.js"
	
	export default {
		name: "MemberWithdrawList",
		data() {
			return {
				list: [],
				loadingStatus: "noMore",
				page: 0,
				withdrawStatus,
				selectedItem: null
			}
		},
		props: {
			adminMode: {
				type: Boolean,
				default: false
			}
		},
		methods: {
			handleItemClick(item) {
				this.selectedItem = item;
				this.$refs.popup.open();
			},
			async reload() {
				if (this.loadingStatus === "loading") {
					return;
				}
				this.list = [];
				this.page = 0;
				this.loadingStatus = "more";
				await this.loadMore();
			},
			async loadMore() {
				if (this.loadingStatus === "loading" || this.loadingStatus === "noMore") {
					return;
				}
				let query = {
					pageNum: this.page + 1,
					pageSize: 20
				}
				let prevStatus = this.loadingStatus;
				this.loadingStatus = "loading";
				try{
					let res = await getMemberWithdrawList(query);
					if (res.records.length) {
						this.list = this.list.concat(res.records);
						this.page += 1;
					}
					if (this.list.length < res.total) {
						this.loadingStatus = "more";
					} else {
						this.loadingStatus = "noMore";
					}
				}catch(e){
					this.$log("获取会员提现列表遇到错误", e);
					this.loadingStatus = prevStatus;
				}
			}
		}
	}
</script>

<style>

</style>
